﻿using System.ComponentModel;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;
using Nutshell.DLS.Business;

namespace Nutshell.DLS.WPFUI
{
        /// <summary>
        ///         MainWindow.xaml 的交互逻辑
        /// </summary>
        public partial class MainWindow
        {
                private readonly GlobalManager _gm = GlobalManager.Instance;

                public MainWindow()
                {
                        InitializeComponent();
                }

                private void Window_OnLoaded(object sender, RoutedEventArgs e)
                {
                        _gm.Start();

                        LayoutRoot.DataContext = _gm;

                        var borard = VisualTreeHelper.GetChild(LogMessagesListBox, 0);
                        var scrollViewer = VisualTreeHelper.GetChild(borard, 0) as ScrollViewer;

                        if (scrollViewer != null)
                        {
                                ((ICollectionView)LogMessagesListBox.Items).CollectionChanged += (ss, se) => scrollViewer.ScrollToEnd();                                
                        }
                }


                private void MainWindow_OnClosing(object sender, CancelEventArgs e)
                {
                        _gm.Stop();
                }
        }
}
